<?php
/**
 * ExtStoreBase class file
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 *          EVALUATION VERSION - NOT FOR COMMERCIAL USE OR DISTRIBUTION.
 * @version 0.7.2
 */
 
 

abstract class ExtStoreBase extends ExtObservableBase
{
    private $_reader_class_types = array('ExtDataReaderBase');
    private $_proxy_class_types = array('ExtDataProxyBase');
    private $_sortinfo_class_types = array('ExtStoreSortInfo');

    public function parseNode(ExtHTMLParserNode $node,
        ExtASTWalker $astwalker)
    {
        parent::parseNode($node, $astwalker);
        $this->renderWriter($node, $astwalker);
        $this->parseReader($node, $astwalker);
        $this->parseData($node, $astwalker);
        $this->parseSortInfo($node, $astwalker);
        $this->parseParameters($node,$astwalker, 'baseparameters', 'baseParams');
        $this->parseProxy($node,$astwalker);
        $node->shiftUp();
    }
    
    private function parseReader($node,$astwalker)
    {
        $reader = $node->findPropertyByName('reader');
        if(!is_null($reader))
        {
            $items=parent::parseNodeWidthTag($reader,
                $astwalker,
                true,
                null,
                $this,
                $this->_reader_class_types);
            $this->setJavaScriptConfig('reader', $items[0]);
            $reader->shiftUp();
        }

    }

    private function parseData($node,$astwalker)
    {
        $data = $this->parseScriptProperty('data', 'data', $node, $astwalker);
        if(!is_null($data))
            $this->setJavaScriptConfig ('proxy','new Ext.data.MemoryProxy()');
    }

    private function parseSortInfo($node,$astwalker)
    {
        $sortinfo = $node->findPropertyByName('sortinfo');
        if(!is_null($sortinfo))
        {
            $items=parent::parseNodeWidthTag($sortinfo,
                $astwalker,
                true,
                array('asobject'=>false),
                $this,
                $this->_sortinfo_class_types);
            $this->setJavaScriptConfig('sortInfo', $items[0]);
            $sortinfo->shiftUp();
        }
    }

    private function parseProxy($node,$astwalker)
    {
        $proxy = $node->findPropertyByName('proxy');
        if(!is_null($proxy))
        {
            $items=parent::parseNodeWidthTag($proxy,
                $astwalker,
                true,
                array('asobject'=>true),
                $this,
                $this->_proxy_class_types);
            $this->setJavaScriptConfig('proxy', $items[0]);
            $proxy->shiftUp();
        }
    }

    private function renderWriter($node,$astwalker)
    {
        $writer = $node->findPropertyByName('writer');
        if(!is_null($writer))
        {
            $items=parent::parseNodeWidthTag($writer,
                $astwalker,
                true,
                array('asobject'=>true),
                $this);
            $this->setJavaScriptConfig('writer', $items[0]);
            $writer->shiftUp();
        }
    }

    public function renderConfig($asobject=true)
    {
        $this->setConfig('storeid', $this->getId());
        return parent::renderConfig($asobject);
    }

    public function createContainer(ExtHTMLParserNode $node)
    {
        return null;
    }
}
?>
